<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>组合</title>
</head>
<body>
<canvas id="canvas" width="400" height="800"></canvas>
<div id="color" style="width: 10px; height: 10px;"></div>
<script>
  var img = new Image();
  img.src = 'aa.jpeg';
  var canvas = document.getElementById('canvas');
  var ctx = canvas.getContext('2d');
  img.onload = function() {
    ctx.drawImage(img, 0, 0);
    img.style.display = 'none';
  };
  var color = document.getElementById('color');
  function pick(event) {
    var x = event.layerX;
    var y = event.layerY;
    var pixel = ctx.getImageData(x, y, 1, 1);
    var data = pixel.data;
    var rgba = 'rgba(' + data[0] + ',' + data[1] + ',' + data[2] + ',' + (data[3] / 255) + ')';
    color.style.background =  rgba;
    color.textContent = rgba;
  }
  canvas.addEventListener('mousemove', pick);
</script>
</body>
</html>